package com.shuoyue.ycgk.utils;

import android.content.Context;

import com.shuoyue.ycgk.appcatch.FileUtil;
import com.umeng.socialize.utils.CommonUtil;

import java.io.File;
import java.io.IOException;

/**
 * 读取唯一编码
 */
public class SimpleCodeUtil {
    public static String getSimpleDeviceCode(Context mContext) {
        String path = FileUtil.getPath(mContext) + "/config";
        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
        File configFile = new File(path, "config.yc");
        if (!configFile.exists()) {
            try {
                configFile.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        String s = FileMannagUtil.getString(configFile.getAbsolutePath());
        return s;
    }

    public static void writeSimpleDeviceCode(Context mContext,String code) {
        String path = FileUtil.getPath(mContext) + "/config/";
        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
        File configFile = new File(path, "config.yc");
        if (configFile.exists()) {
            configFile.delete();
        }
        try {
            configFile.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        FileMannagUtil.writeTxtToFile(code, path, "config.yc");
    }
}
